﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using QQ.Util;
using System.Threading;

using System.Windows.Forms;
using System.Net;

using System.Xml;
using RuoTeng.Util;


namespace RTGather.Lib.gather
{

     
    public class fbb_bugamazon
    {

        private string countpattern = @"(?isx)href=./blog/article/0/0/hot/(?<count>\d*).\sclass=.page-last.>";//总条数  
        private string blogPattern = @"(?isx)grid-author.><a\shref=\u0022(?<content>.*?)\u0022\starget";//博客地址 

        private static string rootpath = Application.StartupPath;//根目录  
        public List<Product> clist = new List<Product>();

        public void getData(string url)
        {

            string innerhtml = Http.GetData(url, null,Encoding.UTF8);
            MatchCollection matches = Regex.Matches(innerhtml, blogPattern);
            if (matches.Count > 0)
            {
                clist.Clear();
                foreach (Match match in matches)
                {
                    GroupCollection groups = match.Groups;
                    string title = groups["content"].ToString();
                    Product p = new Product();
                    p.Name = title;
                    clist.Add(p);
                }

            }
        }

 
 
        public string getStrFromPattern(string pattern,string content,string name)
        {
            Match match = Regex.Match(content, pattern);
            string result="";
            if (match.Success)
            {
                GroupCollection groups = match.Groups;
                result = groups[name].ToString();
            }
            else
            {
                result = "没有登记";
            }
            return result; 
        }

     

        /// <summary>
        /// 根据关键词搜索提取条数
        /// </summary>
        /// <param name="keyword"></param>
        /// <returns></returns>
        public int getCount()
        {
            string url = getUrl(1);
            string result = Http.GetData(url, null, Encoding.Default);

            string count = getStrFromPattern(countpattern, result, "count");
            int num = 0;
            if (count != "没有登记")
            {
                num = ParseType.ParseInt(count, 0);
            }
            return num;
           
        }

        //獲取請求的URL
        public string getUrl(int num)
        {
            string url = string.Format("http://www.pixnet.net/blog/article/0/0/hot/{0}", num);
            return url;
        }
         
       

        /// <summary>
        /// 计算页数 
        /// </summary>
        /// <param name="count"></param>
        /// <returns></returns>
        public int getPageCount(int count)
        { 
            int PageSize = 10; 
            int pagenum = (count / PageSize) + 1; 
            return pagenum;
        }

      
         

    }
}
